﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics.Tracing;

namespace Architecture.CrossCutting.RepositoryPattern.Logging
{
    [EventSource(Name = "ArchitectureResearch-EF-Tracing")]
    public sealed class EFEventSource : EventSource
    {
        public static EFEventSource Log = new EFEventSource();

        public class Keywords
        {
            public const EventKeywords DbCommand = (EventKeywords)1;
            public const EventKeywords Diagnostic = (EventKeywords)4;
            public const EventKeywords Perf = (EventKeywords)8;
        }

        public class Tasks
        {
            public const EventTask DBQuery = (EventTask)1;
        }

        private const int CommandPerformance = 1;
        private const int EventInfo = 2;
        //private const int NonQueryExecuted = 1;
        //private const int NonQueryExecuting = 2;
        //private const int ReaderExecuted = 3;
        //private const int ReaderExecuting = 4;
        //private const int ScalarExecuted = 4;
        //private const int ScalarExecuting = 4;

        

        [Event(CommandPerformance, Keywords = Keywords.Perf, Level =EventLevel.LogAlways, Task = Tasks.DBQuery,
            Message ="Query '{0}' of type '{1}' has been executed in '{2}' ms", Version=1)]
        internal void LogPerformance(String query, String commandType, String providerName, Int64 executionTime)
        {
            this.WriteEvent(CommandPerformance, query, commandType, providerName, executionTime);
        }

        [Event(EventInfo)]
        internal void LogInfo(String message)
        {
            this.WriteEvent(EventInfo, message);
        }


    }
}
